﻿using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using XamlInspector.Foundation;

namespace XamlInspector.Presentation
{
    public class AutoDataTemplateSelector : DataTemplateSelector
    {
        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            var uiElement = (FrameworkElement) container;

            if (item != null)
            {
                var resource = uiElement.FindResource(item.GetType().Name) as DataTemplate;

                if (resource != null)
                {
                    return resource;
                }    
            }

            return base.SelectTemplateCore(item, container);    
        }
    }
}
